
if($.fn.form){
	$.extend($.fn.form.defaults, {
		fieldTypes: ['combobox','combotree','combogrid','datetimebox','datebox','combo',
			'datetimespinner','timespinner','numberspinner','spinner',
			'slider','searchbox','numberbox','filebox','passwordbox','textbox','switchbutton']
	
	});
}
// 解决form load时有file元素异常问题
if($.fn.filebox){
	$.extend($.fn.filebox.methods, {
		setValue: function(jq){
			return jq;
		}
	})
}

// 初始化table
function initEasyuiTable(tableid, url, columnsJson, onDblClickRowfun,
		otherconfig) {
	var rowStyler = function(){};
	var onDblClickRow = {};
	if (onDblClickRowfun)
		onDblClickRow = onDblClickRowfun;
	if (otherconfig && otherconfig.rowStyler) {
		rowStyler = otherconfig.rowStyler;
	}
	$("#" + tableid).datagrid({
		url : urlPre+url,
		columns : [ columnsJson ],
		nowrap : false,
		pagination : true,
		singleSelect : true,
		fitColumns : true,
		autoRowHeight : false,
		rowStyler : rowStyler,
		// queryParams : {
		// "userName" : $("#userName").val(),
		// "sdate" : '',
		// "edate" : ''
		// },
		onDblClickRow : onDblClickRow,
		loadFilter : function(data) {
			return data.data;
		},
		onLoadSuccess : function(data) {
			if (data.code == 1) {
				if (data.total == 0) {
					$.messager.alert('信息提示', "没有找到相关信息！");
				}
			} else if (data.code == 0) {
				$.messager.alert('信息提示', data.msg);
			}

		},
		onLoadError : function() {
			$.messager.alert('信息提示', "服务器访问错误");
		}
	});
}

// 打开ajax的dialog，需要有 id为commonHrefDiailog的html元素
function showCommonHrefDialog(href,width,height,title,onLoad,okbutton){
	if(!width){
		width = 600;
	}
	if(!height){
		height = 400;
	}
	if(!title){
		title = '';
	}
	if(!onLoad){
		onLoad = function(){};
	}
	var buttons = [];
	if(okbutton){
		buttons.push(okbutton);
	}
	buttons.push({
        text:'关闭',
        iconCls:'icon-cancel',
        handler:function(){
            $("#commonHrefDiailog").dialog('close');
        }
    });
	  $("#commonHrefDiailog").dialog({
          href:urlPre+href,
          closed:false,
          width: width,    
          height: height,
          title:title,
          modal:true,
          onLoad:onLoad,
          buttons:buttons
      })
}

// 关闭dialog
function closeCommonHrefDialog(){
	$("#commonHrefDiailog").dialog('close');
}

// ajax封装
function myajax(url, fn, jsonparam, async, showload) {
	var _jsonparam = {};
	var _async = true;
	if (jsonparam) {
		_jsonparam = jsonparam;
	}
	if (typeof (async) != undefined) {
		_async = async;
	}
	if (showload) {
		$.messager.progress();
	}
	$.ajax({
		type : "get",
		url : urlPre+url+'?t='+ new Date().getTime(),
		data : _jsonparam,
		async : _async,
		dataType : "json",
		success : function(data) {
			if (showload) {
				$.messager.progress('close');
			}
			if (data.code == 0) {
				$.messager.alert("错误信息", data.msg, "error");
				return;
			}
			if (data.code == 1) {
				if (fn) {
					fn(data.data);
				}
				return;
			}
			alert(data);
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			if (showload) {
				$.messager.progress('close');
			}
			$.messager.alert("错误信息", '请求出错', "error");
		}
	});
}

// form的ajax提交封装
function formAjax(formid, url, successCallBack, errCallBack) {
	var body = {};
	if (url) {
		body.url = urlPre+url;
	}
	body.success = function(data) {
		var result = eval('(' + data + ')');
		if (result.code == 0) {
			if (errCallBack) {
				errCallBack(result.msg);
			} else {
				$.messager.alert('错误信息', result.msg, 'error');
			}
		} else if (result.code == 1) {
			if (successCallBack) {
				successCallBack(result.data);
			} else {
				$.messager.alert('信息提示', '添加成功', 'info');
			}
		} else {
			alert(result);
		}
	};
	$('#' + formid).form('submit', body);
}

// 带有按钮的dialog封装
function easyuiDialog(divid, okbutHandler, cancelButHandler, heights) {
	var win_h = $(window).height();
	var height = Math.floor(win_h * 0.8);
	if (heights && height > heights) {
		height = heights;
	}
	var top = Math.floor((win_h - height) * 0.5)
	var b = [];
	if (okbutHandler) {
		b.push({
			text : '确定',
			iconCls : 'icon-save',
			handler : okbutHandler
		});
	}
	if (cancelButHandler) {
		b.push({
			text : '取消',
			iconCls : 'icon-cancel',
			handler : cancelButHandler
		});
	}
	return $("#" + divid).dialog({
		height : height,
		top : top,
		closed : false,
		buttons : b
	});
}

// grid封装
function easyuiGrid(formid, url, columns) {
	$('#' + formid)
			.datagrid(
					{
						url : urlPre+url,
						method : 'post', // ie兼容，get不刷新
						columns : [ columns ],
						onLoadSuccess : function(data) {
							if (data.total == 0) {
								var body = $(this).data().datagrid.dc.body2;
								body
										.find('table tbody')
										.append(
												'<tr><td colspan="'
														+ columns.length
														+ '" width="'
														+ body.width()
														+ '" style="height: 35px; text-align: center; color:red"><h1>暂无数据!</h1></td></tr>');
							}
						}

					});
}